package com.glsc.ngateway.common.base.enums.itflow;

import com.glsc.ngateway.common.base.exception.PlatformException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * 流程命名
 *
 * @author xuchang
 * TODO:将流程Flow-Task-Param-Role关联起来
 */
@Getter
@AllArgsConstructor
public enum ITFlowEnum {

    //服务器系统变更
    EQUIPMENT_MODIFY("IT_EQUIPMENT_MODIFY_FLOW", "【国联技术服务平台】服务器系统变更",
            Arrays.asList(
                    //1流程发起
                    ITFlowTaskEnum.MODIFY_FLOW_BEGIN_TASK,
                    //2部门负责人审批
                    ITFlowTaskEnum.MODIFY_FLOW_DEPARTMENT_SUPER_TASK,
                    //3设备管理员库存确认
                    ITFlowTaskEnum.MODIFY_FLOW_DEVICE_ADMIN_TASK,
                    //4信息技术总部基础架构负责人
                    ITFlowTaskEnum.MODIFY_FLOW_FRAMEWORK_HEAD_TASK,
                    //5_1信息技术总部设备管理员审核
                    ITFlowTaskEnum.MODIFY_FLOW_HEAD_QUARTERS_ADMIN_TASK,
                    //5_2病毒管理员审批
                    ITFlowTaskEnum.MODIFY_FLOW_VIRUS_MANAGE_TASK
            )),
    //（虚拟机、云主机）申领
    EQUIPMENT_APPLY("IT_EQUIPMENT_APPLY_FLOW", "【国联技术服务平台】（虚拟机、云主机）申领",
            Arrays.asList(
                    //1流程发起
                    ITFlowTaskEnum.APPLY_FLOW_BEGIN_TASK,
                    //2部门负责人审批
                    ITFlowTaskEnum.APPLY_FLOW_DEPARTMENT_SUPER_TASK,
                    //3设备管理员库存确认
                    ITFlowTaskEnum.APPLY_FLOW_DEVICE_ADMIN_TASK,
                    //4网络安全部门责任人审核
                    ITFlowTaskEnum.APPLY_FLOW_NET_WORK_SECURITY_TASK,
                    //5_1设备管理员分配资源
                    ITFlowTaskEnum.APPLY_FLOW_DEVICE_ADMIN_ASSIGNMENT_TASK,
                    //5_2病毒管理员审批
                    ITFlowTaskEnum.APPLY_FLOW_VIRUS_MANAGE_TASK
            )),
    //设备下架申请
    EQUIPMENT_OFFLINE("IT_EQUIPMENT_OFFLINE_FLOW", "【国联技术服务平台】设备下架申请",
            Arrays.asList(
                    //1流程发起
                    ITFlowTaskEnum.OFFLINE_FLOW_BEGIN_TASK,
                    //2部门负责人审批
                    ITFlowTaskEnum.OFFLINE_FLOW_DEPARTMENT_SUPER_TASK,
                    //3机房管理员处理
                    ITFlowTaskEnum.OFFLINE_FLOW_ROOM_ADMIN_TASK,
                    //4设备管理员库存确认
                    ITFlowTaskEnum.OFFLINE_FLOW_DEVICE_ADMIN_TASK,
                    //5_1网络管理员审核
                    ITFlowTaskEnum.OFFLINE_FLOW_NET_ADMIN_TASK,
                    //5_2病毒管理员审批
                    ITFlowTaskEnum.OFFLINE_FLOW_VIRUS_MANAGE_TASK
            )),
    //物理设备申领及上架
    EQUIPMENT_SERVER_APPLY("IT_EQUIPMENT_SERVER_APPLY_FLOW", "【国联技术服务平台】物理设备申领及上架",
            Arrays.asList(
                    //1流程发起
                    ITFlowTaskEnum.SERVER_APPLY_FLOW_BEGIN_TASK,
                    //2部门负责人审批
                    ITFlowTaskEnum.SERVER_APPLY_FLOW_DEPARTMENT_SUPER_TASK,
                    //3机房管理员审核
                    ITFlowTaskEnum.SERVER_APPLY_FLOW_ROOM_ADMIN_TASK,
                    //4网络管理员审核
                    ITFlowTaskEnum.SERVER_APPLY_FLOW_NET_ADMIN_TASK,
                    //5基础架构部负责人审核
                    ITFlowTaskEnum.SERVER_APPLY_FLOW_HEAD_OF_INFRASTRUCTURE_DEPARTMENT_TASK,
                    //6设备管理员库存确认
                    ITFlowTaskEnum.SERVER_APPLY_FLOW_DEVICE_ADMIN_TASK,
                    //7_1设备管理员库存确认
                    ITFlowTaskEnum.SERVER_APPLY_FLOW_DEVICE_ADMIN_REVIEW_TASK,
                    //7_2病毒管理员审批
                    ITFlowTaskEnum.SERVER_APPLY_FLOW_VIRUS_MANAGE_TASK,
                    //8网络管理员审核
                    ITFlowTaskEnum.SERVER_APPLY_FLOW_NET_ADMIN_REVIEW_TASK
            )),
    //系统命名申请
    SYSTEM_NAME_APPLY("IT_SYSTEM_NAME_APPLY_FLOW", "【国联技术服务平台】系统命名申请",
            Arrays.asList(
                    //1流程发起
                    ITFlowTaskEnum.SYSTEM_NAME_APPLY_FLOW_BEGIN_TASK,
                    //2上级领导审批
                    ITFlowTaskEnum.SYSTEM_NAME_APPLY_FLOW_LEADER_TASK,
                    //3一级部门负责人审批
                    ITFlowTaskEnum.SYSTEM_NAME_APPLY_FLOW_DEPARTMENT_SUPER_TASK
            )),
    //系统命名变更
    SYSTEM_NAME_MODIFY("IT_SYSTEM_NAME_MODIFY_FLOW", "【国联技术服务平台】系统命名变更",
            Arrays.asList(
                    //1流程发起
                    ITFlowTaskEnum.SYSTEM_NAME_MODIFY_FLOW_BEGIN_TASK,
                    //2上级领导审批
                    ITFlowTaskEnum.SYSTEM_NAME_MODIFY_FLOW_LEADER_TASK,
                    //3一级部门负责人审批
                    ITFlowTaskEnum.SYSTEM_NAME_MODIFY_FLOW_DEPARTMENT_SUPER_TASK
            )),
    //配件规格新增/删除
    CMDB_PART_STANDARD_MODIFY("CMDB_PART_STANDARD_MODIFY_FLOW", "【国联技术服务平台】配件规格新增/删除",
            Arrays.asList(
                    //1流程发起
                    ITFlowTaskEnum.CMDB_PART_STANDARD_MODIFY_FLOW_BEGIN_TASK,
                    //2流程发起人确认
                    ITFlowTaskEnum.CMDB_PART_STANDARD_MODIFY_FLOW_CREATOR_AUDIT_TASK
            )),
    //服务器规格新增/删除
    CMDB_DEVICE_STANDARD_MODIFY("CMDB_DEVICE_STANDARD_MODIFY_FLOW", "【国联技术服务平台】服务器规格新增/删除",
            Arrays.asList(
                    //1流程发起
                    ITFlowTaskEnum.CMDB_DEVICE_STANDARD_MODIFY_FLOW_BEGIN_TASK,
                    //2流程发起人确认
                    ITFlowTaskEnum.CMDB_DEVICE_STANDARD_MODIFY_FLOW_CREATOR_AUDIT_TASK
            )),
    //设备入库流程
    CMDB_DEVICE_IN("CMDB_DEVICE_IN_FLOW", "【国联技术服务平台】设备入库",
            Arrays.asList(
                    //1流程发起
                    ITFlowTaskEnum.CMDB_DEVICE_IN_FLOW_BEGIN_TASK,
                    //2上级领导审批
                    ITFlowTaskEnum.CMDB_DEVICE_IN_FLOW_LEADER_TASK,
                    //2流程发起人确认
                    ITFlowTaskEnum.CMDB_DEVICE_IN_FLOW_CREATOR_AUDIT_TASK
            ))
    ,
    //设备出库流程
    CMDB_DEVICE_OUT("CMDB_DEVICE_OUT_FLOW", "【国联技术服务平台】设备出库",
            Arrays.asList(
                    //1流程发起
                    ITFlowTaskEnum.CMDB_DEVICE_OUT_FLOW_BEGIN_TASK,
                    //2上级领导审批
                    ITFlowTaskEnum.CMDB_DEVICE_OUT_FLOW_LEADER_TASK,
                    //2流程发起人确认
                    ITFlowTaskEnum.CMDB_DEVICE_OUT_FLOW_CREATOR_AUDIT_TASK
            ))
    ,
    //配件入库流程
    CMDB_PART_IN("CMDB_PART_IN_FLOW", "【国联技术服务平台】配件入库",
                 Arrays.asList(
                         //1流程发起
                         ITFlowTaskEnum.CMDB_PART_IN_FLOW_BEGIN_TASK,
                 //2上级领导审批
                 ITFlowTaskEnum.CMDB_PART_IN_FLOW_LEADER_TASK,
                 //2流程发起人确认
                 ITFlowTaskEnum.CMDB_PART_IN_FLOW_CREATOR_AUDIT_TASK
                 )),
    //配件出库流程
    CMDB_PART_OUT("CMDB_PART_OUT_FLOW", "【国联技术服务平台】配件出库",
            Arrays.asList(
                    //1流程发起
                    ITFlowTaskEnum.CMDB_PART_OUT_FLOW_BEGIN_TASK,
                    //2上级领导审批
                    ITFlowTaskEnum.CMDB_PART_OUT_FLOW_LEADER_TASK,
                    //2流程发起人确认
                    ITFlowTaskEnum.CMDB_PART_OUT_FLOW_CREATOR_AUDIT_TASK
            )),

    //供应商评价流程
    VENDOR_RATE("IT_VENDOR_RATE", "供应商评价",
                  Arrays.asList(
                          //1流程发起
                          ITFlowTaskEnum.VENDOR_RATE_BEGIN_TASK,
                  //2评估人评分
                  ITFlowTaskEnum.VENDOR_RATE_SCORE_TASK,
                  //3评估人上级确认
                  ITFlowTaskEnum.VENDOR_RATE_LEADER_TASK
                  ))
    ;

    /**
     * id
     */
    private final String key;
    /**
     * desc
     */
    private final String desc;
    /**
     * 节点list
     */
    private final List<ITFlowTaskEnum> taskList;

    public static ITFlowEnum seek(String key) {
        return Arrays.stream(ITFlowEnum.values())
                .filter(o -> o.getKey().equals(key))
                .findFirst()
                .orElseThrow(() -> PlatformException.error(String.format("未找到流程类型:%s", key)));
    }

    public static ITFlowTaskEnum findTask(String flowKey, String taskKey) {
        return seek(flowKey).getTaskList()
                .stream()
                .filter(t -> t.getTaskKey().equals(taskKey))
                .findFirst()
                .orElseThrow(() -> PlatformException.error(String.format("未找到节点类型：%s", taskKey)));
    }
}
